Skip to main content

FrontFetchAsync

Wolfram Kernel
Execution environment
Notebook`Editor`Kernel`FrontSubmitService`
Context

asynchronously evaluates (aka FrontSubmit) and fetches the resulting expression back to the Wolfram Kernel from the frontend (browser)

FrontFetchAsync[expr_, opts___] _Promise

and returns Promise object.

Options

"Window"

specifies a window socket, to which an expression will be sent. Use CurrentWindow to fetch a window object from the evaluation context explicitly.

"Format"

The default expression form used to import raw data acquired from the frontend. It effectively applies ImportString on raw JSON data. The possible values

  • "JSON" (the default)
  • "ExpressionJSON"
  • "Raw" bypasses and returns a string

Usage with Meta-Markers

Using an extension MetaMarker, one can execute an expression in the context of a specified container and fetch the result back

FrontFetchAsync[expr_, m_MetaMarker, opts___] _Promise

See examples on FrontSubmit

Examples

To read the selected text from a cell and print it to another cell

With[{win = CurrentWindow[], cell = ResultCell[]},
EventHandler[InputButton["Read selected text"], Function[Null,

Then[FrontFetchAsync[FrontEditorSelected["Get"], "Window"->win], Function[result,
CellPrint[result
, "After"->cell];
]
]
]]
]

or to read a clipboard of a user

With[{win = CurrentWindow[], cell = ResultCell[]},
EventHandler[InputButton["Read clipboard"], Function[Null,

Then[FrontFetchAsync[ReadClipboard[], "Window"->win], Function[result,
CellPrint[result
, "After"->cell];
]
]
]]
]